# -*- coding: utf-8 -*-
import os
from datetime import datetime
import time
import logging
import json
import requests
import pyodbc
import mysql.connector
import sys



def compare(sid,mid,tablename):
    sql = 'SELECT * FROM '+tablename+'  where ID='    
    # 连接到SQL Server数据库
    conn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.3.147;DATABASE=;UID=sa;PWD=123456')

    # 获取游标
    cursor = conn.cursor()

    # 查询表中的列
    cursor.execute(sql+sid)
    columns = [description[0] for description in cursor.description]
    # 打印列名
    #print(columns)
    row = cursor.fetchone()

    # 关闭连接
    cursor.close()
    conn.close()



    

    # 连接到MySQL数据库
    mconn = mysql.connector.connect(host='192.168.3.147', database='', user='root', password='password')

    # 获取游标
    mcursor = mconn.cursor()

    # 查询表中的列
    mcursor.execute(sql+mid)
    mcolumns = [mcolumn[0] for mcolumn in mcursor.description]
    mrow = mcursor.fetchone()

    set1 = set(row)
    set2 = set(mrow)



    # 打印列名
    #print(mcolumns)
    print( set1 - set2 )
    print("############################################")
    print(set2-set1)

    # 关闭连接
    #mcursor.close()
    mconn.close()


if __name__ == '__main__':
    args = sys.argv[1:]
    #compare(args[0],args[1],args[2])
    # print("******************************************************")
    # print("\n\n\n")
    #compare(args[3],args[4],args[5])
    if len(args)>0 and len(args) % 3 ==0 :
        for n in range(0,len(args),3):
            compare(args[n],args[n+1],args[n+2])
            print("\n\n\n")
            print("******************************************************")
            

    else:
        print("输入参数不正确，参数格式为: SQL_SERVER_ID  MYSQL_ID TABLE_NAME .......")
    